from rest_framework.generics import ListCreateAPIView
from meiduo_admin.user.serializers import UserSerializer
from meiduo_admin import utils
from users.models import User


class UserView(ListCreateAPIView):
    serializer_class = UserSerializer
    pagination_class = utils.MyNumbPage

    def get_queryset(self):
        keyword = self.request.query_params.get('keyword')
        if keyword == '' or keyword is None:
            return User.objects.order_by('id').all()
        else:
            return User.objects.order_by('id').filter(username__contains=keyword)
